package ua.sumdu.LukyanovChalyi.Server;

import java.util.List;
import java.util.ArrayList;

public class Book {

    private List<String> authors;
    private String title;
    private int date;
    private int numberOfPages;

    public Book(List<String> authors, String title, int date, int pages) {
        this.setAuthors(authors);
        this.setTitle(title);
        this.setDate(date);
        this.setNumberOfPages(pages);
    }

    public List<String> getAuthors(){
        return authors;
    }

    public String getTitle() {
        return title;
    }

    public int getDate() {
        return date;
    }

    public int getNumberOfPages() {
        return numberOfPages;
    }

    public void setAuthors(List<String> authors) {
        this.authors = new ArrayList<String>();
        this.authors.addAll(authors);
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public void setDate(int date) {
        this.date = date;
    }

    public void setNumberOfPages(int count) {
        this.numberOfPages = count;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 31 * hash + (null == authors ? 0 : authors.hashCode());
        hash = 31 * hash + (null == title ? 0 : title.hashCode());
        hash = 31 * hash + date;
        hash = 31 * hash + numberOfPages;
        return hash;
    }

    @Override
    public boolean equals(Object other) {
        if (this == other) {
            return true;
        } else if (other == null) {
            return false;
        } else if (!getClass().equals(other.getClass())) {
            return false;
        } else {
            Book book = (Book)other;
            return authors.equals(book.getAuthors()) &&
                    title.equals(book.getTitle()) &&
                    date == book.getDate() &&
                    numberOfPages == book.getNumberOfPages();
        }
    }

    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        List<String> auth = this.getAuthors();
        for (String a:auth){
            sb.append("Author: ").append(a).append("\n");
        }
        sb.append("Title: ").append(this.getTitle()).append("\n");
        sb.append("Imprint Date: ").append(this.getDate()).append("\n");
        sb.append("Pages: ").append(this.getNumberOfPages()).append("\n");
        return sb.toString();
    }
}
